package javabasic;

import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] p = new int[n];
        for(int i=0;i<n;i++){
            p[i] = sc.nextInt();
        }
        Main main = new Main();
        int maxSum = main.maxSum(p,n);
        System.out.print(maxSum);
    }

    public int maxSum(int[] p,int n){
        if(n==1){
            return p[0];
        }
        int[][] dp = new int[n][n];
        for(int i=0;i<n;i++){
            dp[i][i]=p[i];
        }
        int maxNum = Integer.MIN_VALUE;
        for(int i=1;i<n;i++){
            for(int j=0;j<n-i;j++){
                dp[j][j+i]=dp[j][j+i-1]-dp[j+1][j+i]+dp[j+1][j+i-1];
                System.out.print(dp[j][j+i]+" ");
                if(maxNum<dp[j][j+i]){
                    maxNum=dp[j][j+i];
                }
            }
            System.out.println();
        }
        if(maxNum<0){
            return 0;
        }
        for(int i=0;i<n;i++){
            if(maxNum<p[i]){
                maxNum=p[i];
            }
        }
        return maxNum;
    }
}
/*
  public int sumP(int[] p,int low,int high){
        int sum=0;
        for(int i=low;i<=high;i=i+2){
            sum=sum+p[i];
        }
        for(int i=low+1;i<=high;i=i+2){
            sum=sum-p[i];
        }
        return sum;
    }
 */